<?php
	namespace home;
	use BaseController,View; 
	use Request,Input,Redirect,Response;
	use QuanHuyen,THPT,NganhNghe,KhoiXet;
	class AjaxController extends BaseController{
		public function loadQuanHuyenByTinh(){
			if(Request::ajax()){
				// Here process
				$idTinh = trim(Input::get('idTinh'));
				$quanhuyen = QuanHuyen::select('Huyen','TenHuyen')
									  ->where('Tinh',"=",$idTinh)
									  ->get();
				return View::make('default.ajax.quanhuyen')->with("quanhuyens",$quanhuyen);
			}
		}
		public function loadTruongTHPTByTinh(){
			if(Request::ajax()){
				// Here process
				$idTinh = trim(Input::get('idTinh'));
				$truong = THPT::select('idTHPT','TenTruong','DiaChi')
									  ->where('Tinh',"=",$idTinh)
									  ->get();
				return View::make('default.ajax.truongthpt')->with("truongs",$truong);
			}
		}
		public function loadNganhNgheByNganh(){
			if(Request::ajax()){
				// Here process
				$idNganh = trim(Input::get('idNganh'));
				$nganhnghes = NganhNghe::select('idNganh','Name','Dot1','Dot2','Dot3','KhoiXetTuyen')
									  ->where('idNganh',"=",$idNganh)
									  ->get()->first()->toJson();
				return $nganhnghes;
			}
		}
		public function loadNameKhoiXet(){
			if(Request::ajax()){
				// Here process
				$tenkhoi = trim(Input::get('KhoiXet'));
				$khoixets = KhoiXet::select('idKhoiXet','TenKhoi','Mon1','Mon2','Mon3')
									->where('TenKhoi',"=",$tenkhoi)
									->where('HienThi',"=",1)
									->get()->first()->toJson();
				return $khoixets;
			}
		}
		// Check Xử lý phần Đậu Rớt
		public function daurot(){
			if(Request::ajax()){
				// Here process
				$data = array(
					'diemchuan'	=>	trim(Input::get('diemchuan')),
					'doituong'	=>	Input::get('doituong'),
					'khuvuc'	=>	trim(Input::get('khuvuc')),
					// Học kỳ I 11
					'txtHK1_11_Mon1'	=>	trim(Input::get('txtHK1_11_Mon1')),
					'txtHK1_11_Mon2'	=>	trim(Input::get('txtHK1_11_Mon2')),
					'txtHK1_11_Mon3'	=>	trim(Input::get('txtHK1_11_Mon3')),
					// Học kỳ II 11
					'txtHK2_11_Mon1'	=>	trim(Input::get('txtHK2_11_Mon1')),
					'txtHK2_11_Mon2'	=>	trim(Input::get('txtHK2_11_Mon2')),
					'txtHK2_11_Mon3'	=>	trim(Input::get('txtHK2_11_Mon3')),
					// Học kỳ I 12
					'txtHK1_12_Mon1'	=>	trim(Input::get('txtHK1_12_Mon1')),
					'txtHK1_12_Mon2'	=>	trim(Input::get('txtHK1_12_Mon2')),
					'txtHK1_12_Mon3'	=>	trim(Input::get('txtHK1_12_Mon3')),
				);
				if(CheckDauRot($data)){
					$ketqua = array("mess" => true,"KetQua" => "Đậu",200);
				}else{
					$ketqua = array("mess" => false,"KetQua" => "Rớt");
				}
				return json_encode($ketqua);
			}
		}
	}
?>